package com.gk.javaservice.util.base;

import java.io.File;

public class FormatName {
    /**
     * Rename the file.
     */
    public static boolean rename(final File file, final String newName) {
        // file is null then return false
        if (file == null) return false;
        // file doesn't exist then return false
        if (!file.exists()) return false;
        // the new name equals old name then return true
        if (newName.equals(file.getName())) return true;
        File newFile = new File(file.getParent() + File.separator + newName);
        // the new name of file exists then return false
        return !newFile.exists()
                && file.renameTo(newFile);
    }

    public static String formatName(String name){
        Long startTs = System.currentTimeMillis(); // 当前时间戳
        String t1=startTs+"";
        t1=t1.substring(10);
        String s1=name.substring(name.indexOf("月")+2,name.indexOf("月")+6);
        // System.out.println("s1:"+s1);
        String s2=name.substring(name.indexOf("月")+9,name.indexOf("月")+17);
        // System.out.println("s2:"+s2);
        String s3=name.substring(name.lastIndexOf("."));
        // System.out.println("s3:"+s3);
        String newName=s1+s2+t1+s3;
        newName=newName.replaceAll("-","");
        // System.out.println("newName:"+newName);
        return newName;
    }

    //去除空格
    public static String formatName2(String name){
        String newName=name.replaceAll(" ","");

        return newName;
    }
}
